<script setup lang="ts">
import HomeBackground from "@/layout/blog/HomeBackground.vue";
import SvgIcon from "@/components/SvgIcon/index.vue";
import UserProfileCard from "@/views/homeLayout/home/UserProfileCard.vue";
import WeatherAndTime from "@/views/homeLayout/home/WeatherAndTime.vue";
import {getRecentlyArticleUrl} from "@/api/blog/article.ts";
import ArticleCard from "@/views/homeLayout/home/ArticleCard.vue";
import VueCalHeatmap from "@/views/homeLayout/home/VueCalHeatmap.vue";
import BlogContent from "@/components/BlogContent/index.vue";
import BlogFooter from "@/layout/blog/BlogFooter.vue";

const recentlyArticle = ref([])
const total = ref(0)
const getList = () => {
  getRecentlyArticleUrl().then((res: any) => {
    recentlyArticle.value = res.rows || []
    total.value = res.total
  })
}

onMounted(() => {
  // getList()
})

</script>

<template>
  <div>
    <HomeBackground></HomeBackground>
    <BlogContent class="home-content" id="app-home">
      <!-- 展示最近发布的文章信息  -->
      <template #content class="recently-published-articles">
        <div class="card">
          <!--  标题  -->
          <div class="card-title">
            <div class="card-title-left">
              <SvgIcon size="26" class-name="blog-recently-icon" icon-class="blog-recently"></SvgIcon>
              <span>最新文章</span>
            </div>
            <div class="card-title-action el-link">
              <span>更多</span>
              <SvgIcon size="16" icon-class="more"></SvgIcon>
            </div>
          </div>
          <!--  分界线        -->
          <div class="card-dashed"></div>
          <template v-if="total <= 0">
            <el-empty style="margin: 60px auto"></el-empty>
          </template>
          <div v-else class="card-content">
            <template v-for="(item, index) in recentlyArticle" :key="index">
              <ArticleCard :article="item"></ArticleCard>
            </template>
          </div>
          <div class="card-footer">
            <span v-if="total <= recentlyArticle.length">~没有更多了~</span>
            <span v-else >点击加载更多</span>
          </div>
        </div>
      </template>
      <!-- 展示自己的资料卡片 -->
      <template #sidebar>
        <UserProfileCard class="box-shadow-card"></UserProfileCard>
        <VueCalHeatmap class="box-shadow-card"></VueCalHeatmap>
        <WeatherAndTime class="box-shadow-card"></WeatherAndTime>
      </template>
    </BlogContent>
    <BlogFooter class="blog-footer"></BlogFooter>
  </div>
</template>

<style scoped lang="scss">
/* 首页的样式 */
.home-content {
  /*左右分布*/
  display: flex;
  justify-content: space-between;
  margin: 36px auto;
  max-width: 1160px;

  .recently-published-articles {
    width: 75%;
    margin-right: 16px;

    .recently-published-article {
      height: 260px;
    }
  }

  .profile-cards {
    width: 296px;
  }

  @media screen and (max-width: 870px) {
    .recently-published-articles {
      width: 100%;
      margin: 0 16px;
    }
    .profile-cards {
      display: none;
    }
  }


  .card {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;

    .card-title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 26px;
      font-size: 14px;
      line-height: 26px;
      padding: 0 8px;
      .card-title-left {
        display: flex;
        align-items: center;
      }
      .card-title-action {
        height: 100%;
        display: flex;
        align-items: center;
        line-height: 26px;
      }
    }

    .card-dashed {
      height: 2px;
      width: 100%;
      border-bottom: 1px dashed $blog-primary-light-1;
    }

    .card-content {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      grid-gap: 16px;
      margin-top: 18px;
      padding-bottom: 36px;
      position: relative;
    }
  }
}

.card-footer {
  width: 100%;
  text-align: center;
  font-size: 12px;
  font-weight: bold;
}
</style>
